package com.ruoyi.mall.controller;

import java.util.List;

import com.ruoyi.mall.entity.MallPackages;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.service.IMallPackagesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 卡包Controller
 * 
 * @author ruoyi
 * @date 2020-05-25
 */
@Controller
@RequestMapping("/mall/packages")
public class MallPackagesController extends BaseController
{
    private String prefix = "mall/packages";

    @Autowired
    private IMallPackagesService mallPackagesService;

    @RequiresPermissions("mall:packages:view")
    @GetMapping()
    public String packages()
    {
        return prefix + "/packages";
    }

    /**
     * 查询卡包列表
     */
    @RequiresPermissions("mall:packages:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MallPackages mallPackages)
    {
        startPage();
        List<MallPackages> list = mallPackagesService.selectMallPackagesList(mallPackages);
        return getDataTable(list);
    }

    /**
     * 导出卡包列表
     */
    @RequiresPermissions("mall:packages:export")
    @Log(title = "卡包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MallPackages mallPackages)
    {
        List<MallPackages> list = mallPackagesService.selectMallPackagesList(mallPackages);
        ExcelUtil<MallPackages> util = new ExcelUtil<MallPackages>(MallPackages.class);
        return util.exportExcel(list, "packages");
    }

    /**
     * 新增卡包
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存卡包
     */
    @RequiresPermissions("mall:packages:add")
    @Log(title = "卡包", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MallPackages mallPackages)
    {
        return toAjax(mallPackagesService.insertMallPackages(mallPackages));
    }

    /**
     * 修改卡包
     */
    @GetMapping("/edit/{packageId}")
    public String edit(@PathVariable("packageId") Long packageId, ModelMap mmap)
    {
        MallPackages mallPackages = mallPackagesService.selectMallPackagesById(packageId);
        mmap.put("mallPackages", mallPackages);
        return prefix + "/edit";
    }

    /**
     * 修改保存卡包
     */
    @RequiresPermissions("mall:packages:edit")
    @Log(title = "卡包", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MallPackages mallPackages)
    {
        return toAjax(mallPackagesService.updateMallPackages(mallPackages));
    }

    /**
     * 删除卡包
     */
    @RequiresPermissions("mall:packages:remove")
    @Log(title = "卡包", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mallPackagesService.deleteMallPackagesByIds(ids));
    }
}
